load data.mat

U_H1 = compute(table1)
U_H2 = compute(table2)
B2 = U_H2(:,2)./(21.*4)
U_H3 = compute(table3)
U_H4 = compute(table4)
U_H5 = compute(table5)
B5 = U_H5(:,2)./(2779.*4)
disp('*******************************')

disp('是否绘制图像？1表示是，0代表否： ')
judge = input('')
if judge == 0
    disp('已结束！')
elseif judge ==1
    disp('请输入需要绘制图像的table序列号： ')
    t = input('')
    if t == 1
        polyfit(U_H1(:,2),U_H1(:,1),1)
        disp('线性拟合')
        k = ans(1,1)
        b = ans(1,2)
        plot(U_H1(:,2),U_H1(:,1),'o')
        xlabel('霍尔电压 U_H / mV')
        ylabel('工作电流 I_S / mA')
        title('U_H - I_S 图像')
        hold on
        grid on
        f = @(x)k.*x+b;
        xinterval = [4,22];
        fplot(f,xinterval);
    end
    if t == 2
        polyfit(B2,U_H2(:,1),1)
        disp('线性拟合')
        k = ans(1,1)
        b = ans(1,2)
        plot(B2,U_H2(:,1),'o')
        xlabel('磁感应强度 B / T')
        ylabel('励磁电流 I_M / mA')
        title('B - I_M 图像')
        hold on
        grid on
        f = @(x)k.*x+b;
        xinterval = [0.05,0.25];
        fplot(f,xinterval);
    end
    if t == 3
        polyfit(U_H3(:,2),U_H3(:,1),1)
        disp('线性拟合')
        k = ans(1,1)
        b = ans(1,2)
        plot(U_H3(:,2),U_H3(:,1),'o')
        xlabel('霍尔电压 U_H / mV')
        ylabel('工作电流 I_S / mA')
        title('U_H - I_S 图像')
        hold on
        grid on
        f = @(x)k.*x+b;
        xinterval = [20,65];
        fplot(f,xinterval);
    end
    if t == 4
        polyfit(U_H4(:,2),U_H4(:,1),1)
        disp('线性拟合')
        k = ans(1,1)
        b = ans(1,2)
        plot(U_H4(:,2),U_H4(:,1),'o')
        xlabel('霍尔电压 U_H / mV')
        ylabel('工作电流 I_S / mA')
        title('U_H - I_S 图像')
        hold on
        grid on
        f = @(x)k.*x+b;
        xinterval = [20,110];
        fplot(f,xinterval);
    end
    if t == 5
        plot(U_H5(:,1),B5,'o--')
        ylabel('磁感应强度 B / T')
        xlabel('螺线管距离 X / mm')
        title('X - B 图像')
        hold on
        grid on
        scatter(U_H5(:,1),B5)
    end
end

function[M] = compute(table)
Table = abs(table)
[m,n] = size(Table)
M = zeros(m,2)
M(:,1) = table(:,1)
for i = 1:m
    M(i,2) = mean(Table(i,[2:5]))
end
end

function[] = LeastSquare(U_H)
f = @(x)k.*x+b;
xinterval = [2,8];
fplot(f,xinterval);
end